package com.example.spring.service;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.spring.entity.Worker;
import com.example.spring.mapper.WorkerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkerService {
    @Autowired
    private WorkerMapper workerMapper;

    public int save(Worker worker){
        if(worker.getWkid() == null) { //无id新增id
            return workerMapper.insert_data(worker);
        }
        else {//否则更新
            return workerMapper.update(worker);
        }
    }
    //返回wkid(正数）代表用户正确，返回0代表没找到这用户
    public Integer find_password(Worker worker)
    {
        String username = worker.getUsername();
        String name = worker.getName();
        String tel = worker.getTel();
        List<Worker> workerList = workerMapper.forgetPassword(username, name, tel);
        if (!workerList.isEmpty()) return  workerList.get(0).getWkid();
        else return 0;
    }

}
